define(['jquery', 'bootstrap', 'backend', 'table', 'form','template','vue'], function ($, undefined, Backend, Table, Form,Template,Vue) {
    function initSearchVue() {
        var vue = new Vue({
            el:'#search_div',
            data:{
                province_list: [],
                city_list: [],
                county_list: [],
                village_list: [],
                province_id : 0,
                city_id : 0,
                county_id : 0,
                village_id : 0,
            },
            watch:{
                province_id:function (val) {
                    this.province_id = val;
                    this.getCityList();
                    this.village_list = [];
                },
                city_id:function (val) {
                    this.city_id = val;
                    this.getCountyList();
                    this.village_list = [];
                },
                county_id:function (val) {
                    this.county_id = val;
                    this.getVillageList();
                }
            },
            methods: {
                getProvinceList:function(){
                    var that = this;
                    $.post("adminpublic/ajax_get_region_list", {
                        parent_id : 0
                    }, function (res) {
                        that.province_list = res;
                    });
                },
                getCityList:function(){
                    var that = this;
                    $.post("adminpublic/ajax_get_region_list", {
                        parent_id : that.province_id
                    }, function (res) {
                        that.city_list = res;
                    });
                },
                getCountyList:function(){
                    var that = this;
                    $.post("adminpublic/ajax_get_region_list", {
                        parent_id : that.city_id
                    }, function (res) {
                        that.county_list = res;
                    });
                },
                getVillageList:function(){
                    var that = this;
                    $.get("adminpublic/ajax_village_list", {
                        county_id : that.county_id
                    }, function (res) {
                        that.village_list = res;
                    });
                }
            }
        });
        vue.getProvinceList();
        return vue;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            var type = Config.type;
            Table.api.init({
                extend: {
                    index_url: 'log/importlog/index?type='+type
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                search:false,
                columns: [
                    [
                        {field: 'id', title: 'ID',sortable:true},
                        {field: 'remark', title: __('Remark'),sortable:false},
                        {field: 'admin_user', title: __('Operation admin'),searchable:false},
                        {field: 'village_name', title: __('Village name'),searchable:false},
                        {field: 'status', title: __('Status'),formatter:function(value,row,index){
                            value = value + '';
                            switch (value){
                                case '0':
                                    return __('Import fail');
                                case '1':
                                    return __('Import success');
                            }
                        },searchList: {'0': __('Import fail'), '1': __('Import success')}, style: 'min-width:100px;'
                        },
                        {field: 'type', title: __('Type'),formatter:function(value,row,index){
                            value = value + '';
                            switch (value){
                                case '0':
                                    return __('House import');
                                case '1':
                                    return __('Free import');
                            }
                        },searchable:false, style: 'min-width:100px;'
                        },
                        {field: 'village_id', title: __('Village'),visible:false,searchList: function (column) {
                            return Template('village_search', {});
                        }
                        },
                        {field: 'create_time', title: __('Create time'),
                            formatter: Table.api.formatter.datetime, operate: 'BETWEEN',
                            type: 'datetime', addclass: 'datetimepicker',
                            data: 'data-date-format="YYYY-MM-DD"'
                        }
                    ]
                ]
            });
            initSearchVue();
            // 为表格绑定事件
            Table.api.bindevent(table);
        }
    };
    return Controller;
});